package assist;
import java.util.concurrent.CountDownLatch;
/**
 * @author lyx
 * @version 1.0
 * @since 1.8
 * @Date 2021/6/25 11:01
 *
 * 辅助类-减法计数器
 * 例子:10个人离开教室后关门
 */
public class CountDownLatchTest {
    public static void main(String[] args) throws InterruptedException {
        //总数10,必须执行任务的时候,再使用!
        CountDownLatch countDownLatch = new CountDownLatch(10);
        for (int i = 1; i <= 10; i++) {
            new Thread(()->{
                countDownLatch.countDown(); //数量 -1
                System.out.println(Thread.currentThread().getName()+"  Get out");
            },String.valueOf(i)).start();
        }
        countDownLatch.await();//*******等待结果为0时,操作下一步;
        System.out.println("人已经走完,关门!");
    }

}
